package akka.mapreduce.actors

import akka.actor._
import akka.mapreduce._

class ReduceActor extends Actor {
  
  def receive = {
    case MapData(datalist) => sender ! reduce(datalist)
  }

  def reduce(words: IndexedSeq[WordCount]): ReduceData = ReduceData {
    words.foldLeft(Map.empty[String, Int]) { (index, words) =>
      if (index contains words.word)
        index + ( words.word -> (index.get(words.word).get + 1))
      else
        index + (words.word -> 1)
    }
  }
}
